package com.newvpn.fastbest.zenith.dialog;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.newvpn.fastbest.zenith.BuildConfig;
import com.newvpn.fastbest.zenith.R;
import com.newvpn.fastbest.zenith.utils.VLog;


public class VersionDialog extends BaseDialog {

    private static final String ARG_VER = "versionName";
    private static final String ARG_CONTENT = "content";
    private static final String ARG_FORE = "isFore";
    //private Button ok;

    public static VersionDialog newInstance(String versionName,String content, boolean isFore) {
        VersionDialog fragment = new VersionDialog();
        Bundle args = new Bundle();
        args.putString(ARG_VER, versionName);
        args.putString(ARG_CONTENT, content);
        args.putBoolean(ARG_FORE, isFore);
        fragment.setArguments(args);
        return fragment;
    }


    @Override
    protected int layout() {
        return R.layout.v_dialog_version;
    }

    @Override
    protected void init(View view) {
        View ok = view.findViewById(R.id.ok);
        boolean isFore  = getArguments().getBoolean(ARG_FORE);
        ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                VLog.event("Update_Click");
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse("https://play.google.com/store/apps/details?id=" + BuildConfig.APPLICATION_ID));
                startActivity(intent);
                if (!isFore){
                    dismiss();
                }
            }
        });
        View cancel = view.findViewById(R.id.cancel);
        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
        String versionName = getArguments().getString(ARG_VER);
        String content = getArguments().getString(ARG_CONTENT);;
        cancel.setVisibility(isFore?View.GONE:View.VISIBLE);
        TextView tvVersion  = view.findViewById(R.id.tvVersion);
        tvVersion.setText(versionName);
        TextView tvVersionInfo  = view.findViewById(R.id.tvVersionInfo);
        tvVersionInfo.setText(content);


    }




}

